import {Component, OnInit} from '@angular/core';
import {CommonService} from "../../service/base/common.service";
import {NzModalService} from "ng-zorro-antd/modal";
import {HttpCustomConfig} from "../../service/base/base.http.service";
import {UserHttpService} from "../../service/http/user.http.service";

@Component({
  selector: 'app-user',
  templateUrl: './user.component.html',
  styleUrls: ['./user.component.less']
})
export class UserComponent implements OnInit {
  dataList: any[] = [];
  pageIndex: number = 1;
  pageSize: number = 15;
  pageTotal: number = 0;
  mobile: string = '';
  shareUserNo: string = '';
  userNo: string = '';
  userId: string = '';
  memberFilter: string = '';
  memberFilterList = [
    {value: '', label: '全部会员'},
    {value: 'yes', label: '仅限会员'}];

  constructor(private userHttpService: UserHttpService) {
  }

  defaultHttpConfig: HttpCustomConfig = {showLoading: false}

  ngOnInit() {
    this.queryData()
  }

  queryDataInit(): void {
    this.pageIndex = 1;
    this.queryData();
  }

  queryData(): void {
    this.userHttpService.queryUserAll({
      pageIndex: this.pageIndex,
      pageSize: this.pageSize,
      memberFilter: this.memberFilter,
      mobile: this.mobile,
      userId: this.userId,
      userNo: this.userNo,
      shareUserNo: this.shareUserNo
    }, this.defaultHttpConfig).subscribe((res) => {
      this.dataList = res.data.dataList
      this.pageTotal = res.data.total;
    })
  }

  save(data: any): void {
    this.userHttpService.updateUserMember({
      userId: data.userId,
      memberExpireTime: data.memberExpireTime,
      shareUserNo: data.shareUserNo
    }, this.defaultHttpConfig).subscribe((res) => {
      this.queryData();
    })
  }
}
